package cn.com.smartdevices.bracelet.chart.base;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/* renamed from: cn.com.smartdevices.bracelet.chart.base.a */
public class BarChart extends BaseChart<BarChart.BarItem> { // C0719a
    protected float mItemPadding; //f3799c;
    protected int mMaxItemValue; //f3800d;
    protected int f3801e;
    public Axis mXAxis; //f3802f;
    protected Axis mYAxis; //f3803g;
    protected boolean mMirrored; //f3804h;
    protected boolean mNeedRealign; //f3805i;

    public BarChart(Context context) {
        super(context);
    }

    public static class BarItem  extends BaseChart<Item> { // C0726c
        public int f3883b;
        public int f3884c;
        public int f3885d;
        public boolean f3886e;

        public BarItem(Context context) {
            super(context);
        }

        protected void draw(Canvas canvas, RectF rectF, float f) {
            if (this.f3886e && this.mRenderer != null) {
                float width = (rectF.width() / 2.0f) + rectF.left;
                float f2 = rectF.bottom;
                float width2 = (rectF.width() / 2.0f) + rectF.left;
                float height = rectF.bottom - (rectF.height() * f);
                this.mRenderer.f3958c.setStrokeWidth(rectF.width());
                canvas.drawLine(width, f2, width2, height, this.mRenderer.f3958c);
            }
        }

        protected void draw(Canvas canvas, RectF rectF, float f, boolean z) {
            if (this.f3886e && this.mRenderer != null) {
                if (z) {
                    float width = (rectF.width() / 2.0f) + rectF.left;
                    float f2 = rectF.top;
                    float width2 = (rectF.width() / 2.0f) + rectF.left;
                    float height = (rectF.height() * f) + rectF.top;
                    this.mRenderer.f3958c.setStrokeWidth(rectF.width());
                    canvas.drawLine(width, f2, width2, height, this.mRenderer.f3958c);
                    return;
                }
                draw(canvas, rectF, f);
            }
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Value : " + this.f3883b).append(" , ");
            stringBuilder.append("Index : " + this.f3884c).append(" , ");
            stringBuilder.append("Scope : " + this.f3885d).append(" , ");
            stringBuilder.append("NeedDrow : " + this.f3886e);
            return stringBuilder.toString();
        }
    }

    public class BarItemComparator  implements Comparator<BarItem> { // C0751d
        public int compare(BarItem c0726c, BarItem c0726c2) {
            return c0726c.f3884c - c0726c2.f3884c;
        }
    }

    public class YAxis extends Axis { //C0752f
        public YAxis(Context context) {
            super(context);
        }

        protected void draw(Canvas canvas, RectF rectF, float f) {
            canvas.drawRect(rectF, mRenderer.f3958c);
        }
    }

    public class XAxis extends Axis { // C0723e
        public XAxis(Context context) {
            super(context);
        }

        protected void draw(Canvas canvas, RectF rectF, float f) {
            canvas.drawRect(rectF, this.mRenderer.f3958c);
        }
    }

    public abstract class Axis extends BaseChart<Item> { //C0722b
        public int value; //f3839f;
        public int offset; //f3840g;
        public int stroke; //f3841h;

        public Axis(Context context) {
            super(context);
        }
    }



    protected float itemWidth (RectF rectF, BarItem c0726c) { // m8311a
        return (rectF.width() / ((float) this.mItems.size())) - (this.mItemPadding * 2.0f);
    }

    protected void draw(Canvas canvas, RectF rectF, float f) {
        synchronized (this.mItems) {
            int size = this.mItems.size();
            for (int i = 0; i < size; i++) {
                ((BarItem) this.mItems.get(i)).draw(canvas, f, this.mMirrored);
            }
        }
        if (this.mXAxis != null) {
            this.mXAxis.draw(canvas, f);
        }
        if (this.mYAxis != null) {
            this.mYAxis.draw(canvas, f);
        }
    }

    protected void onRectChanged (RectF rectF) { // m8313a
        RectF rectF2;
        if (this.mXAxis != null) {
             rectF2 = new RectF();
            rectF2.left = rectF.left;
            rectF2.top = rectF.bottom - ((float) this.mXAxis.stroke);
            rectF2.right = rectF.right;
            rectF2.bottom = rectF.bottom;
            this.mXAxis.setRect(rectF2);
        }
        if (this.mYAxis != null) {
            rectF2 = new RectF();
            rectF2.left = rectF.left;
            rectF2.top = rectF.top;
            rectF2.right = rectF.left + ((float) this.mYAxis.stroke);
            rectF2.bottom = rectF.bottom;
            this.mYAxis.setRect(rectF2);
        }
        this.mNeedRealign = true;
    }

    protected void realignItems (RectF rectF, List<? extends BarItem> list) { // m8314a
        if (rectF != null && list != null && list.size() != 0) {
            for (BarItem c0726c : list) {
                if (m8316a(c0726c)) {
                    RectF rectF2;
                    float a;
                    c0726c.f3886e = true;
                    if (this.mNeedRealign || c0726c.mRect == null) {
                        if (c0726c.mRect == null) {
                            c0726c.mRect = new RectF();
                        }
                        rectF2 = c0726c.mRect;
                        a = itemWidth(rectF, c0726c);
                        float b = itemHeight(rectF, c0726c);
                        if (this.mMirrored) {
                            rectF2.top = rectF.top + this.mPaddingTop;
                            rectF2.bottom = b + rectF2.top;
                        } else {
                            rectF2.bottom = rectF.bottom - this.mPaddingBottom;
                            rectF2.top = rectF2.bottom - b;
                        }
                    } else {
                        rectF2 = c0726c.mRect;
                        a = rectF2.width();
                    }
                    rectF2.left = rectF.left + this.mItemPadding;
                    rectF2.right = a + rectF2.left;
                    rectF2.offset(itemOffsetX(rectF, c0726c), 0.0f);
                } else {
                    c0726c.f3886e = false;
                }
            }
            this.mNeedRealign = false;
        }
    }

    public void setNeedRealign (boolean z) { // m8315a
        this.mNeedRealign = z;
    }

    protected boolean m8316a(BarItem c0726c) {
        return true;
    }

    protected void onItemsChanged(List<BarItem> list) {
        for (BarItem c0726c : list) {
            c0726c.mDensity = this.mDensity;
            c0726c.mDensityScale = this.mDensityScale;
        }
        this.mNeedRealign = true;
    }

    protected float itemHeight (RectF rectF, BarItem c0726c) { // m8317b
        return c0726c.f3883b >= this.mMaxItemValue ? (rectF.height() - this.mPaddingTop) - this.mPaddingBottom : (((float) c0726c.f3883b) / ((float) this.mMaxItemValue)) * ((rectF.height() - this.mPaddingTop) - this.mPaddingBottom);
    }

    protected float itemOffsetX (RectF rectF, BarItem c0726c) { // m8318c
        return (rectF.width() / ((float) this.mItems.size())) * ((float) this.mItems.indexOf(c0726c));
    }

    public void setItemPadding (float f) { // m8319c
        this.mItemPadding = f;
    }

    protected float itemOffsetY (RectF rectF, BarItem c0726c) { // m8320d
        return 0.0f;
    }

    public void notifyChanged () { // m8321e
        synchronized (this.mItems) {
            realignItems(this.mRect, this.mItems);
        }
    }

    public int getMaxItemValue () { // m8322i
        return this.mMaxItemValue;
    }

    public void setMaxItemValue (int i) { //m8323i
        this.mMaxItemValue = i;
    }

    public int m8324j() {
        return this.f3801e;
    }

    public void m8325j(int i) {
        this.f3801e = i;
    }

    public void sortItems () { // m8326k
        synchronized (this.mItems) {
            Collections.sort(this.mItems, new BarItemComparator());
        }
    }
}
